<template>
  <div class="edit-wrap">
    <div class="edit-btn">
      <a-space>
        <a-button type="primary" @click="addApply">{{ $t('all.autotext1125') }}</a-button>
      </a-space>
    </div>
    <a-descriptions
      class="charge-tab"
      :title="$t('all.autotext106')"
      :column="4"
      style="margin: 20px 0 0"
    >
      <a-descriptions-item :label="item.name" v-for="(item, i) in detailscharge" :key="i">
        ￥{{ item.num }}
      </a-descriptions-item>
    </a-descriptions>
    <a-tabs v-model="current" @change="tabChange">
      <a-tab-pane v-for="(item, i) in deition" :key="i" :tab="item"></a-tab-pane>
    </a-tabs>
    <div style="border-bottom:1px solid #E5EBF3;border-left:1px solid #E5EBF3;">
      <a-row class="visit-row" type="flex">
        <a-col flex="106px" style="overflow: hidden;">
          <div class="col-head back-col">
            <div class="visit-charge-title">{{ $t('all.autotext789') }}</div>
            <div class="visit-charge-tab">（{{ $t('all.autotext750') }}）</div>
          </div>
          <div class="col-item back-col" v-for="(item, i) in types" :key="i">
            <a-tooltip :title="item.applyType">
              <div class="visit-charge-title">{{ item.applyType }}</div>
            </a-tooltip>
            <div v-if="item.defaulted && item.amt">({{ $t('money.unit') }}{{ item.amt }})</div>
          </div>
        </a-col>
        <a-col flex="1" style="overflow: hidden;">
          <div class="col-title" style="border-left:1px solid #E5EBF3;">
            <div class="col-title-text">{{ deition[current] }}</div>
            <a-popover :title="$t('all.autotext615')" placement="topRight">
              <template slot="content">
                <a-row class="popover-row" :gutter="[0, 20]" style="width:500px;">
                  <a-col :span="8">
                    <div style="width:20px;height:20px;background:#F4F7F9;"></div>
                    <span>{{ $t('all.autotext47') }}</span>
                  </a-col>
                  <a-col :span="8">
                    <div style="color:#ABB8CE;padding:0 6px;">{{ $t('money.unit') }}123</div>
                    <span>{{ $t('all.autotext750') }}</span>
                  </a-col>
                  <a-col :span="8">
                    <div style="padding:0 8px;">-</div>
                    <span>{{ $t('all.autotext1464') }}</span>
                  </a-col>
                  <a-col :span="8">
                    <div style="padding:0 6px;">{{ $t('money.unit') }}123</div>
                    <span>{{ $t('all.autotext867') }}</span>
                  </a-col>
                  <a-col :span="16">
                    <div style="color:#F02F2F;padding:0 6px;">{{ $t('money.unit') }}123</div>
                    <span>申请≠默认</span>
                  </a-col>
                  <!-- <a-col :span="8">
                    <div style="color:#ABB8CE;background:rgba(240, 47, 47, 0.04);text-decoration:line-through;padding:0 6px;">{{ $t('money.unit') }}123</div>
                    <span>{{ $t('all.autotext938') }}</span>
                  </a-col> -->
                  <a-col :span="16">
                    <div style="color:#ABB8CE;height:20px;line-height:18px;font-size:20px;"><a-icon type="more" /></div>
                    <span>{{ $t('all.autotext555') }}</span>
                  </a-col>
                </a-row>
              </template>
              <img class="col-icon" src="../../image/view-icon4.png" />
            </a-popover>
          </div>
          <div style="width:100%;overflow-x:auto;">
            <div style="white-space:nowrap;display:flex;">
              <div class="col-name gary-col col-inline" v-for="(item, i) in lists" :key="i">
                <a-tooltip>
                  <template slot="title">
                    <div>{{ item.name }}</div>
                    <div>{{ item.stage }}</div>
                  </template>
                  <div class="col-name-tab">{{ item.name }}</div>
                  <div class="col-name-tab">{{ item.stage }}</div>
                </a-tooltip>
                <!-- <div style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
                  <a-tooltip :title="item.stage">
                    {{ item.stage }}
                  </a-tooltip>
                </div> -->
              </div>
            </div>
            <div style="white-space:nowrap;">
              <div v-for="(item, i) in types" :key="i" style="display:flex;">
                <div class="col-inline" v-for="(val, e) in item.visitVersionRecords" :key="e">
                  <a-popover
                    :title="$t('all.autotext404')"
                    placement="topRight"
                    v-if="val.applyDetailList && val.applyDetailList.length>0"
                  >
                    <template slot="content">
                      <a-table :columns="columns" :data-source="val.applyDetailList" :pagination="false">
                        <template slot="status" slot-scope="text, record">
                          <span>{{ record.status | enumValueByKey($const.COST_TYPES) }}</span>
                        </template>
                      </a-table>
                    </template>
                    <item-num :val="val" />
                  </a-popover>
                  <item-num v-else :item="item" :val="val" />
                </div>
              </div>
            </div>
          </div>
        </a-col>
      </a-row>
    </div>
  </div>
</template>
<script>
import { getPtsCostDetails } from '@/api/overview/subject'
import { getApprovalDetail } from '@/api/overview/approval'
import itemNum from './itemNum'
export default {
  components: { itemNum },
  props: ['visible', 'pts', 'id'],
  data () {
    return {
      proId: '',
      researchApprovalInfo: '',
      detailscharge: [
        // {
        //   name: this.$t('all.autotext1331'),
        //   num: 0
        // },
        {
          name: this.$t('all.autotext1351'),
          num: 0
        },
        {
          name: this.$t('all.autotext589'),
          num: 0
        }
        // {
        //   name: this.$t('all.autotext68'),
        //   num: 0
        // }
      ],
      visitVersionList: [],
      current: 0,
      columns: [
        {
          title: this.$t('all.autotext334'),
          align: 'center',
          customRender: (text, record, index) => `${index + 1}`
        },
        {
          dataIndex: 'apply_type',
          key: 'apply_type',
          title: this.$t('all.autotext1236')
        },
        {
          dataIndex: 'visit_record_info',
          key: 'visit_record_info',
          title: this.$t('all.autotext1049')
        },
        {
          dataIndex: 'status',
          key: 'status',
          title: this.$t('all.autotext1498'),
          scopedSlots: { customRender: 'status' }
        },
        {
          dataIndex: 'amount',
          key: 'amount',
          title: this.$t('all.autotext867')
        },
        {
          dataIndex: 'apply_no',
          key: 'apply_no',
          title: this.$t('all.autotext1156')
        }
      ],
      deition: [], // 版本数组
      types: [],
      lists: [] // 表头访视阶段
    }
  },
  watch: {
    visible (val) {
      if (!val) return
      this.getDetails()
    }
  },
  created () {
    this.getProjectId()
  },
  mounted () {
    this.getDetails()
    this.initApproval()
  },
  methods: {
    async getDetails () {
      const res = await getPtsCostDetails({ id: this.id })
      // this.detailscharge[0].num = res.totalPrime.budgetPrice
      this.detailscharge[0].num = res.totalPrime.payPrice
      this.detailscharge[1].num = res.totalPrime.applyPrice
      // this.detailscharge[3].num = res.totalPrime.breakAwayFromPrice
      this.visitVersionList = res.visitVersionList
      this.deition = res.visitVersionList.map(item => this.$t('all.autotext1432') + item.name)
      this.lists = res.visitVersionList[this.current].visitVersionList
      this.types = res.visitVersionList[this.current].proFlowFeeCategories
    },
    tabChange (e) {
      this.lists = this.visitVersionList[e].visitVersionList
      this.types = this.visitVersionList[e].proFlowFeeCategories
    },
    // 获取项目id
    getProjectId () {
      const pro = localStorage.getItem('CURRENT_PROID')
      if (pro) {
        this.proId = parseInt(pro)
      }
    },
    // 获取审批流详情
    async initApproval () {
      const proId = this.proId
      this.researchApprovalInfo = await getApprovalDetail({
        proId,
        type: 2
      })
    },
    addApply () {
      if (!this.researchApprovalInfo) return this.$message.warning(this.$t('all.autotext1780'))
      // 受试者费用
      this.$router.push({
        name: 'AddSubject',
        query: {
          pname: this.$store.state.user.project.name,
          id: this.proId,
          reId: this.pts.reId,
          ptsTypeRoleId: this.pts.ptsTypeRoleId,
          ptsNo: this.pts.ptsNo
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
.edit-wrap {
  position: relative;
}
.edit-btn {
  position: absolute;
  right: 0;
  z-index:100;
}
.charge-tab {
  /deep/.ant-descriptions-item-content{
    font-size: 18px;
    font-weight: bold;
  }
}
.back-col {
  background: #fff;
}
.gary-col{
  background: #fff;
}
.visit-row {
  background:#E5EBF3;
  border-top:1px solid #E5EBF3;
  border-top:1px solid #E5EBF3;
  border-right:1px solid #E5EBF3;
}
.col-head {
  width: 100%;
  height: 100px;
  display: flex;
  flex-direction: column;
  // align-items: center;
  justify-content: center;
  overflow: hidden;
  text-align:center;
}
.col-item {
  height: 60px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-top:1px solid #E5EBF3;
  text-align:center;
}
.col-title {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(246, 249, 251, 1);
  position: relative;
  .col-icon {
    width: 20px;
    height: 20px;
    position: absolute;
    right: 20px;
  }
}
.col-name {
  height: 60px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align:center;
  padding: 10px;
  background: rgb(239, 241, 243);
  color: #4D5C6F;
  overflow: hidden;
  .col-name-tab {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
.col-inline {
  border-left:1px solid #E5EBF3;
  flex:1;
  min-width:200px;
  vertical-align: middle;
}
.popover-row {
  .ant-col {
    white-space: nowrap;
    div {
      display: inline-block;
      vertical-align: middle;
      border: 1px solid #eee;
    }
    span {
      vertical-align: middle;
      font-size: 12px;
      margin-left: 6px;
    }
    .popover-icon {
      width: 20px;
      height: 20px;
      vertical-align: middle;
    }
  }
}
.visit-charge-title {
  font-size: 16px;
  padding: 0 6px 0 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.visit-charge-tab {
  color:#8193B1;
}
</style>
